const express = require('express');
const path = require('path');
const app = express();
const request = require('request');
const port = 4001;
// 配置静态文件服务中间件
let serverUrl = ' http://flowadmin.yjuji.com/';
//server地址index.html和node代码在一个目录下

app.use('/static', express.static('public'));

app.use('/', function (req, res) {
  let url = serverUrl + req.url;
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Methods", "GET, PUT, PATCH, POST, DELETE");
  res.header("Access-Control-Allow-Headers", "*")
  req.pipe(request(url)).pipe(res);
});

app.listen(port, '127.0.0.1', function () { //前端ajax地址写 http://127.0.0.1:3000/
  console.log(`server is running at port ${port}`);
});


// var express = require('express');
// var proxy = require('http-proxy-middleware');
// var app = express();


// app.use('/', proxy({
//   target: 'http://flowadmin.yjuji.com/',
//   changeOrigin: true
// }));
// app.listen(3000);